/**
* Copyright (C) 2013-2024 Nanjing Pengyun Network Technology Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ 

package py.infocenter.authorization;

import static org.junit.Assert.assertEquals;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import py.icshare.authorization.PyResource;
import py.icshare.authorization.ResourceStore;
import py.test.TestBase;


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {InformationCenterDbConfigTest.class})
public class ResourceDbStoreTest extends TestBase {

  private static final Logger logger = LoggerFactory.getLogger(ResourceDbStoreTest.class);

  @Autowired
  private ResourceStore resourceStore;

  @Before
  public void init() {
    resourceStore.cleanResources();
  }

  /**
   * Test save resource. * Test step: 1. Create a resource and save it; 2. Get resource by id and
   * also by name, compare resource get from database and the resource created.
   */
  @Test
  public void testSaveResource() {
    PyResource resource = new PyResource(1L, "volume1", PyResource.ResourceType.Volume.name());
    resourceStore.saveResource(resource);
    PyResource resourceGetById = resourceStore.getResourceById(1L);
    assertEquals(resource, resourceGetById);
    PyResource resourceGetByName = resourceStore.getResourceByName("volume1");
    assertEquals(resource, resourceGetByName);

  }

  @Test
  public void testDeleteResource() {

  }

  @After
  public void clean() {
    resourceStore.cleanResources();
  }
}
